package org.bookie.model.services.impl;

import java.io.Serializable;
import java.util.List;

/**
 * Generic DAO Interface
 * 
 * @author zubairov
 * @see http://www.hibernate.org/328.html
 *
 * @param <T>
 * @param <ID>
 */
public interface GenericDAO<T, ID extends Serializable> {

    /**
     * Finds all instances by given ID with lock parameter
     * @param id
     * @param lock
     * @return
     */
	T findById(ID id, boolean lock);

    /**
     * Finds all instances by given ID with lock parameter set to false
     * @param id
     * @return
     */
	T findById(ID id);
	
	
	/**
	 * Returns all instances
	 * @return
	 */
	List<T> findAll();
	
	/**
	 * Returns all instances ordered 
	 * @param asc order by asc or not
	 */
	List<T> findAllOrdered(boolean asc, String propertyName);

    /**
     * Returns instance by given example
     * @param exampleInstance
     * @return
     */
	public List<T> findByExample(T exampleInstance, String... excludeProperty);

    /**
     * Stores transient instance in the database
     * @param entity
     * @return
     */
	T makePersistent(T entity);

    /**
     * Deleted persistent entity from the database
     * @param entity
     */
	void makeTransient(T entity);
	
	T merge(T entity);
	
	void rollbackTransaction();
}